﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyNhaSach.DataAccessLayer
{
    public class KhachHangDAO
    {
        DataConnection dt_con = new DataConnection();
        public KhachHangDAO()
        {

        }
        public DataTable TimKiemTen(string key)
        {
            return dt_con.Read("exec KHACHHANG_SearchName '" + key + "'");
        }
        public DataTable TimKiemMaKH(string key)
        {
            return dt_con.Read("exec KHACHHANG_SearchID'" + key + "'");
        }
        public DataTable LayDanhSach()
        {
            return dt_con.Read("exec KHACHHANG_Get");
        }

        public void ThemKhachHang(string makh, string tenkh, string diachi, string sdt)
        {
            string cmd = "exec KHACHHANG_Insert '{0}',N'{1}',N'{2}','{3}'";
            dt_con.Write(String.Format(cmd, makh, tenkh, diachi, sdt));
        }

        public void ThayDoiTTKH(string makh, string tenkh, string diachi, string sdt)
        {
            string cmd = "exec KHACHHANG_UPDATE '{0}',N'{1}',N'{2}','{3}'";
            dt_con.Write(String.Format(cmd, makh, tenkh, diachi, sdt));
        }

        public DataTable KiemTraTonTai(string makh)
        {
            string cmd = "exec KHACHHANG_Check '{0}'";
            return dt_con.Read(string.Format(cmd,makh));
        }

        public DataTable LayTTKH(string makh)
        {
            return dt_con.Read("select * form KHACHHANG where MaKH = '" + makh + "' ");
        }
    }
}
